window.onload = function () {
    new Vue({
        el: '#app',
        data: {
            mySwiper: {},
            phoneType: '',
            deviceType: '',
            phone: '',
            downloadLink: '123'
        },
        created() {
            this.getPhoneType()
            this.getDeviceType()
            this.getPhone()
            this.setPoint('visitor')
        },
        mounted() {
            this.setDownloadLink()
            this.initSwiper()
        },
        methods: {
            getDeviceType() {
                var uA = navigator.userAgent

                if (uA.indexOf('Android') > -1 || uA.indexOf('Adr') > -1) {
                    return this.deviceType = 'android'
                }

                if (!!uA.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
                    return this.deviceType = 'ios'
                }
            },
            initSwiper() {
                this.mySwiper = new Swiper('.swiper-container', {
                    speed: 300,
                    paginationClickable: true,
                    direction: 'vertical',
                    preloadImages: true,
                    lazyLoadingOnTransitionStart: true
                });
            },
            setDownloadLink() {
                console.log(this.deviceType)
                if (this.deviceType == 'ios') {

                    this.downloadLink = 'itms-apps://itunes.apple.com/cn/app/%E5%AF%86%E5%8F%8B%E5%9C%88/id1266608463?mt=8"'

                    this.setPoint("download")
                } else if (this.deviceType == 'android') {

                    this.downloadLink = 'http://rcsoa-nopay.zone139.com/versionmanager/download/meetyou-release/' + this.getUrlParam("channel")
                }
            },
            handleWeixin(e) {
                if (this.isWeixin()) {
                    e.preventDefault()
                    this.$refs.popup.classList.add('isshow')
                    this.$refs.mask.classList.add('isshow')
                    this.mySwiper.lockSwipes()
                }
            },
            setPoint(type) {
                var param;

                param = {
                    "systemType": this.phoneType,
                    "channel": this.getUrlParam("channel"),
                    "operatorType": type,
                    "mobileNumber": this.phone
                }

                this.$http.get("http://rcsoa-nopay.zone139.com/versionmanager/download/meetyou-record", {
                    params: param,
                    responseType: 'json'
                }).then(res => {
                    if (res.status === 200) {
                        console.log(res.body)
                    }
                }, res => {
                    console.log(res)
                })
            },
            getPhoneType() {
                var uA = navigator.userAgent.toLowerCase()

                if (/(iphone|ipod|ipad);?/i.test(uA)) {
                    return this.phoneType = "ios"
                }

                if (/android|adr/.test(uA) && !(/windows phone/.test(uA))) {
                    return this.phoneType = "android"
                }
            },
            getUrlParam(name) {
                var reg, target;

                reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
                target = window.location.search.substr(1).match(reg)

                return target ? target[2] : null
            },
            getPhone() {
                this.$http.get("http://120.197.89.223/app/phoneget.do").then((res) => {
                    this.phone = res
                })
            },
            isWeixin() {
                return navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"
            }
        }
    })
}